package cn.cloud.all.security.oauth2.provider.expression;

import cn.cloud.all.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import cn.cloud.all.security.core.Authentication;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class OAuth2MethodSecurityExpressionHandler extends DefaultMethodSecurityExpressionHandler {

    public OAuth2MethodSecurityExpressionHandler() {
        setExpressionParser(new OAuth2ExpressionParser(getExpressionParser()));
    }

    @Override
    public StandardEvaluationContext createEvaluationContextInternal(Authentication authentication, MethodInvocation mi) {
        StandardEvaluationContext ec = super.createEvaluationContextInternal(authentication, mi);
        ec.setVariable("oauth2", new OAuth2SecurityExpressionMethods(authentication));
        return ec;
    }
}
